package com.smart.campus.controller;

import com.smart.campus.dto.ShDepartment;
import com.smart.campus.pojo.PagedResponse;
import com.smart.campus.pojo.ResponseResult;
import com.smart.campus.service.ShDepartmentServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @BelongsProject: smart-campus
 * @BelongsPackage: com.smart.campus.controller
 * @Author: JinBao shan
 * @date 2024/9/19 17:20
 * @Description: TODO
 * @Version: 1.0
 */

@Api(tags = "部门管理模块")
@Slf4j
@RestController
@RequestMapping(value = "dept")
public class ShDepartmentController {
    @Autowired
    private ShDepartmentServiceFeign departmentServiceFeign;

    @ApiOperation(value = "部门列表分页查询",httpMethod = "POST",notes = "部门列表分页查询")
    @RequestMapping(value = "findShDepartmentsPagination")
    public ResponseResult<PagedResponse<ShDepartment>> findShDepartmentsPagination(@RequestBody ShDepartment department, @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        return new ResponseResult<>(200,"部门列表分页查询成功",departmentServiceFeign.findShDepartmentsPagination(department,pageNum,pageSize));
    }

    @ApiOperation(value = "部门列表查询", httpMethod = "GET", notes = "部门列表查询")
    @RequestMapping(value = "getShDepartmentList")
    public ResponseResult<List<ShDepartment>> getShDepartmentList(){
        return new ResponseResult<>(200,"部门列表信息获取成功",departmentServiceFeign.getShDepartmentList());
    }

    @ApiOperation(value = "部门信息新增",httpMethod = "POST",notes = "部门信息新增")
    @RequestMapping(value = "addShDepartment")
    public ResponseResult addShDepartment(@RequestBody ShDepartment department){
        try {
            departmentServiceFeign.addShDepartment(department);
            return new ResponseResult<>(200,"部门信息新增成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"部门信息新增失败");
        }
    }

    @ApiOperation(value = "部门信息回显",httpMethod = "POST",notes = "部门信息回显")
    @RequestMapping(value = "getShDepartmentById")
    public ResponseResult<ShDepartment> getShDepartmentById(Integer id){
        return new ResponseResult<>(200,"根据部门id获取部门信息成功",departmentServiceFeign.getShDepartmentById(id));
    }

    @ApiOperation(value = "部门信息修改",httpMethod = "POST",notes = "部门信息修改")
    @RequestMapping(value = "updateShDepartmentById")
    public ResponseResult updateShDepartmentById(@RequestBody ShDepartment department){
        try {
            departmentServiceFeign.updateShDepartmentById(department);
            return new ResponseResult<>(200,"部门信息修改成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"部门信息修改失败");
        }
    }

    @ApiOperation(value = "部门状态修改",httpMethod = "POST",notes = "部门状态修改")
    @RequestMapping(value = "updateShDepartmentStatusById")
    public ResponseResult updateShDepartmentStatusById(@RequestBody ShDepartment department){
        try {
            departmentServiceFeign.updateShDepartmentStatusById(department);
            return new ResponseResult<>(200,"部门状态修改成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"部门状态修改失败");
        }
    }

    @ApiOperation(value = "部门信息删除",httpMethod = "POST",notes = "部门信息删除")
    @RequestMapping(value = "deleteShDepartmentById")
    public ResponseResult deleteShDepartmentById(@RequestParam(value = "id") Integer id){
        try {
            departmentServiceFeign.deleteShDepartmentById(id);
            return new ResponseResult<>(200,"部门信息删除成功");
        } catch (Exception e) {
            return new ResponseResult<>(444,"部门信息删除失败");
        }
    }
}
